// 使用abstract声明抽象类
abstract class MyAbstractClass {
  void myMethod();
}

// 使用as进行类型转换
void main() {
  var myObject = MyClass() as MyAbstractClass;
  myObject.myMethod();

  main2();
  main3();
}

// dynamic类型变量示例
void main2() {
  dynamic myDynamicVar = 10;
  print("myDynamicVar: $myDynamicVar");
  myDynamicVar = "Hello";
  print("myDynamicVar: $myDynamicVar");
}

// extension扩展String类型
extension MyExtension on String {
  String get extendedValue => "Extended: $this";
}

// 外部函数声明
external int myExternalFunction();

// 工厂模式创建实例
class MyFactoryClass {
  factory MyFactoryClass() {
    return MyFactoryClass._internal();
  }
  MyFactoryClass._internal();
}

// 函数类型别名
typedef MyFunctionType = void Function();

// getter方法实现
class MyClassWithGetter {
  final int _myValue = 5;
  int get myValueGetter => _myValue;
}

// 类实现接口方法
class MyImplementationClass implements MyAbstractClass {
  @override
  void myMethod() {
    print("MyImplementationClass 的 myMethod");
  }
}

// 延迟初始化示例
class MyLateClass {
  late String myLateVariable;
  void initialize() {
    myLateVariable = "Initialized Late";
  }
}

// 运算符重载实现
class MyOperatorClass {
  int value = 10;
  MyOperatorClass operator +(MyOperatorClass other) {
    return MyOperatorClass()..value = value + other.value;
  }
}

// 必填参数标记
class MyRequiredClass {
  MyRequiredClass({required this.myRequiredParameter});
  final String myRequiredParameter;
}

// 密封类定义
sealed class MySealedClass {}

class MySealedSubClass1 extends MySealedClass {}

class MySealedSubClass2 extends MySealedClass {}

// setter方法实现
class MyClassWithSetter {
  int _myValue = 0;
  set myValueSetter(int newValue) {
    _myValue = newValue;
  }

  int get myValueGetter => _myValue;
}

// 静态成员定义
class MyStaticClass {
  static int myStaticVariable = 20;
  static void myStaticMethod() {
    print("MyStaticClass 的 myStaticMethod");
  }
}

// 父类方法调用
class MyChildClass extends MyClass {
  @override
  void myMethod() {
    super.myMethod();
    print("MyChildClass 的 myMethod");
  }
}

// 同步生成器实现
Iterable<int> countSynchronously(int n) sync* {
  for (int i = 1; i <= n; i++) {
    yield i;
  }
}

// 无返回值函数示例
void myVoidFunction() {
  print("This is a void function");
}

// main函数补充逻辑
void main3() {
  var factoryInstance = MyFactoryClass();
  print("Factory Instance: $factoryInstance");

  var getterClass = MyClassWithGetter();
  print("Getter Value: ${getterClass.myValueGetter}");

  var synchronousNumbers = countSynchronously(3);
  print("Synchronous Numbers: $synchronousNumbers");

  myVoidFunction();
}

// 抽象类具体实现
class MyClass implements MyAbstractClass {
  @override
  void myMethod() {
    print("MyClass 的 myMethod 方法被调用");
  }
}